#include "Cursor.h"

bool Cursor::addToBoard( PenteBoard *board ){
	bool ret = false;
	if( board != NULL ) {
		if( board->getNode(0) != NULL ) {
			pGameBoard = board;
			pBoardNode = board->getNode(0);

			pBoardNode->setCursorOn();

			ret = true;
		}
	}

	return ret;
}

void Cursor::moveCursor( int direction ) {
	PenteBoardNode *next;

	if( pBoardNode != NULL ) {
		if( pBoardNode->hasNeighbor( direction ) ) {
			next = pBoardNode->getDirectionalNodes( direction );
			pBoardNode->setCursorOff();
			next->setCursorOn();
			cursorPos.setXY( next->getPos()->getX(), next->getPos()->getY() );
			pBoardNode = next;
		}
	}
}

void Cursor::drawCursor( Screen *disp ) {
	int player = pGameBoard->getActivePlayer();
	WORD color;

	#ifdef DEBUGMODE
		printf( "player 1 Color: %d\nplayer 2 Color: %d\n", PLAYER_ONE_COLOR, PLAYER_TWO_COLOR );
	#endif



	if( player == PLAYER_ONE ) {
		color = PLAYER_ONE_COLOR;
	} else if( player == PLAYER_TWO ) {
		color = PLAYER_TWO_COLOR;
	}

	#ifdef DEBUGMODE
		printf( "in drawCursor()...\nplayer is %d\nColor is %d\n", player, color );
	#endif

	disp->setAt( pBoardNode->getCenterX(), pBoardNode->getCenterY(), CURSOR, color );
}